package com.nuanshui.heatedloan.controller.display.credit;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSON;
import com.nuanshui.heatedloan.constant.GlobalParam;
import com.nuanshui.heatedloan.controller.BaseController;
import com.nuanshui.heatedloan.credit.facade.CustomerBaseInfoService;
import com.nuanshui.heatedloan.credit.form.CustomerBaseInfoForm;
import com.nuanshui.heatedloan.credit.vo.CustomerBaseInfoVO;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by wangxw on 2017/6/27.
 */
@RequestMapping("customerBaseInfoController")
@RestController
public class CustomerBaseInfoController  extends BaseController {

    @Reference(url = GlobalParam.CREDIT_DUBBO_SERVER, timeout = GlobalParam.DUBBO_SERVER_TIME_OUT,version = GlobalParam.CREDIT_DUBBO_SERVER_VERSION)
    private CustomerBaseInfoService customerBaseInfoService;

    @RequestMapping(value = "/addCustomerBaseInfo",method = RequestMethod.POST)
    public String addCustomerBaseInfo(String customBaseInfoMsg) {
        CustomerBaseInfoForm customBaseInfoForm = JSON.parseObject(customBaseInfoMsg, CustomerBaseInfoForm.class);
        String userId= getCurrentUser().getId();
        customBaseInfoForm.setUserId(userId);
        customBaseInfoForm.setStatus("1");
        if (customBaseInfoForm.getId() != null) {
            customerBaseInfoService.updateCustomerBaseInfo(customBaseInfoForm);
        } else {
            customerBaseInfoService.saveCustomerBaseInfo(customBaseInfoForm);
        }
        return success(customBaseInfoForm);
    }

    @RequestMapping(value = "/getCustomerBaseInfoById",method = RequestMethod.POST)
    public String getCustomerBaseInfoById(String id) {
        CustomerBaseInfoVO customerBaseInfoVO = customerBaseInfoService.loadVO(id);
        return success(customerBaseInfoVO);
    }


    @RequestMapping(value = "/deleteCustomerBaseInfoById",method = RequestMethod.POST)
    public String deleteCustomerBaseInfoById(String id) {
        customerBaseInfoService.deleteCustomerBaseInfo(id);
        return success();
    }

    @RequestMapping(value = "/getCustomerBaseInfoByUserId",method = RequestMethod.POST)
    public String getCustomerBaseInfoByUserId(){
        String userId= getCurrentUser().getId();
        CustomerBaseInfoVO customerBaseInfoVO =  customerBaseInfoService.getCustomerBaseInfoByUserId(userId);
        return success(customerBaseInfoVO);
    }

}



